package com.wedo.mall.activity.main;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.e.library.activity.EActivity;
import com.e.library.http.EApi;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;
import com.wedo.mall.R;
import com.wedo.mall.entity.Banner;

import java.util.Map;

import butterknife.BindView;
import io.reactivex.Observable;

/**
 * Created by lxy on 2017/6/19.
 */

public class BannerActivity extends EActivity{

    @BindView(R.id.iv_banner) ImageView iv_banner;
    @BindView(R.id.tv_banner) TextView tv_banner;

    @Override
    protected int layout() {
        return R.layout.activity_banner;
    }

    @Override
    protected void onActivityCreated(Bundle state) {
        final Banner banner = getIntent().getParcelableExtra("banner");

        Glide.with(this).load(banner.image).diskCacheStrategy(DiskCacheStrategy.ALL).into(iv_banner);

        loading();
        Observable<EResponse> observable = api().bannerDetail(banner.id);
        observer(observable, new EObserver() {
            @Override
            public void successful(EResponse response) {
                Map<String,String> map = response.object("list", Map.class);
                String content = map.get("content");
                tv_banner.setText(content);
            }

            @Override
            public void failure(String msg) {
                tv_banner.setText(banner.content);
            }

            @Override
            public void onComplete() {
                super.onComplete();
                dismiss();
            }
        });



    }
}
